//
//  personalInfoVC.m
//  tcpoctest
//
//  Created by gump on 10/26/12.
//  Copyright (c) 2012 gump. All rights reserved.
//

#import "personalInfoVC.h"
#import "WFLabel_blackShadow.h"
#import "PublicFun.h"
#import "ViewManager.h"
#import "FirendInfo.h"
#import "chatuserdb.h"
#import "EGOPhotoGlobal.h"
#import "MyPhotoSource.h"
#import "MyPhoto.h"
#import "BigImageInfo.h"
#import "CareDataSource.h"

#import "sendNewsLength.h"
#import "sendPotocol.h"
#import "sendHeadImageBig.h"
#import "sendGiftGetStroage.h"
#import "sendGiftListLength.h"
#import "sendPersonReadCoin.h"

#import "FirCirPersonDataSource.h"
#import "GiftInfoDataSource.h"
#import "giftStroageDataSource.h"

#import "giftStroageDataInfo.h"

#import <QuartzCore/QuartzCore.h>

#import "chatDataSource.h"
#import "PersonalSignCell.h"

#import "bigHeadImageDataSource.h"

@interface personalInfoVC ()

@end

@implementation personalInfoVC

- (id)init
{
    self = [super init];
    if (self) {
        smallImageArr = [[NSMutableArray alloc] init];
        mtablev = nil;
        
        isSearching = false;
        iWaitingTimer = 0;
        readbigcount = 0;
        isReadingbigimage = false;
    }
    return self;
}

-(void)initUI
{
    [self createTitle];
    self.mtitle.text = @"详细资料";
    
    [self createHeadView];//初始化headview
    
    mtablev =[[UITableView alloc]initWithFrame:CGRectMake(0, TOPBAR_HIGHT, WINDOW_WIDTH, WINDOW_HIGTH - TOPBAR_HIGHT - 20)
                                         style:UITableViewStyleGrouped];
    mtablev.backgroundColor = CELL_BG_COLOR;
    mtablev.separatorStyle = UITableViewCellSeparatorStyleNone;
    mtablev.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bgColor.png"]];
    mtablev.backgroundView = nil;
    mtablev.tableHeaderView = headView;
    mtablev.delegate = self;
    mtablev.dataSource =self;
    [self.view addSubview:mtablev];
    
    [self createtoolbar];
    
    UIBarButtonItem *backItem = [self createBarBackButtonItemWithTitle:@"返回" target:self action:@selector(backButtonPressed)];
    self.navItem.leftBarButtonItem = backItem;
}


#pragma mark - 初始化headview
-(void)createHeadView
{
    if ([DataControl shareControl].currentFI == nil) {
        return;
    }
    
    headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 88)];
    headView.backgroundColor = [UIColor clearColor];
    
    //用户头像
    headImgView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 15, 65, 65)];
    headImgView.userInteractionEnabled = YES;
    NSString *imageurl = [[DataControl shareControl] SearchHeadImage:
                          [DataControl shareControl].currentFI.mail];
    if ([imageurl length] > 0)
    {
        headImgView.image = [UIImage imageWithContentsOfFile:imageurl];
        headImgView.layer.cornerRadius = 8.0f;
        headImgView.layer.borderWidth = 1.0f;
        headImgView.layer.masksToBounds = YES;
        headImgView.layer.borderColor = [[UIColor clearColor] CGColor];
    }
    else
    {
        headImgView.image = [UIImage imageNamed:@"default_head.png"];
    }
    [headView addSubview:headImgView];
    
    //在图片上添加点击事件
    UITapGestureRecognizer *singleTouch = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    [headImgView addGestureRecognizer:singleTouch];
    
    //姓名的label
    nameLabel = [[UILabel alloc]initWithFrame:CGRectZero];
    nameLabel.backgroundColor = [UIColor clearColor];
    nameLabel.textColor = [UIColor blackColor];
    nameLabel.textAlignment = NSTextAlignmentLeft;
    nameLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17.0f] ;
    nameLabel.text = [DataControl shareControl].currentFI.name;
    [headView addSubview:nameLabel];
    
    //性别的图片
    sexIcon = [[UIImageView alloc]initWithFrame:CGRectZero];
    if ([DataControl shareControl].currentFI.sex == 1){
        sexIcon.image = [UIImage imageNamed:@"icon_male.png"];
    }
    else{
        sexIcon.image = [UIImage imageNamed:@"icon_female.png"];
    }
    [headView addSubview:sexIcon];
    
    //碰碰帐号的label
    PPidLabel = [[UILabel alloc]initWithFrame:CGRectMake(85, 50, 124, 21)];
    PPidLabel.backgroundColor = [UIColor clearColor];
    PPidLabel.textColor = [UIColor colorWithWhite:0.4 alpha:1.0];
    PPidLabel.textAlignment = NSTextAlignmentLeft;
    PPidLabel.font = [UIFont systemFontOfSize:14.f];
    PPidLabel.text = [NSString stringWithFormat:@"%@号:%d"
                      ,T_PROJECTNAME
                      ,[DataControl shareControl].currentFI.ippnum];
    [headView addSubview:PPidLabel];
    
//    [self changeCellSize];//动态控制控件的坐标
}

-(void)viewDidAppear:(BOOL)animated{
    [self changeCellSize];//动态控制控件的坐标
}


#pragma mark - 自定义宽度
-(void)changeCellSize{
    CGSize constraint = CGSizeMake(210, 1000);//label宽度设为200，高度最多为1000
    CGSize theSize = [[DataControl shareControl].currentFI.name sizeWithFont:[UIFont systemFontOfSize:17.0f] constrainedToSize:constraint lineBreakMode:NSLineBreakByCharWrapping];//根据文字的多少来设定行高
    
    nameLabel.frame = CGRectMake(85, 15, theSize.width+10, 22);//昵称的坐标
    sexIcon.frame = CGRectMake(theSize.width + 95, 19, 16, 16);//性别的图片
    
    
}


#pragma mark - 加载headview
-(void)reloadHeadView
{
    if ([DataControl shareControl].currentFI == nil) {
        return;
    }
    
    NSString *imageurl = [[DataControl shareControl] SearchHeadImage:
                          [DataControl shareControl].currentFI.mail];
    if ([imageurl length] > 0)
    {
        headImgView.image = [UIImage imageWithContentsOfFile:imageurl];
        headImgView.layer.cornerRadius = 8.0f;
        headImgView.layer.borderWidth = 1.0f;
        headImgView.layer.masksToBounds = YES;
        headImgView.layer.borderColor = [[UIColor clearColor] CGColor];
    }
    else
    {   headImgView.layer.masksToBounds = NO;
        headImgView.image = [UIImage imageNamed:@"default_head.png"];
    }
    
    nameLabel.text = [DataControl shareControl].currentFI.name;
    
    if ([DataControl shareControl].currentFI.sex == 1)
    {
        sexIcon.image = [UIImage imageNamed:@"icon_male.png"];
    }
    else
    {
        sexIcon.image = [UIImage imageNamed:@"icon_female.png"];
    }
    
    PPidLabel.text = [NSString stringWithFormat:@"%@号:%d"
                      ,T_PROJECTNAME
                      ,[DataControl shareControl].currentFI.ippnum];
}

-(void)createtoolbar
{
    UIImageView *toolbar = [[UIImageView alloc]initWithFrame:CGRectMake(0.0f,
                                                                        WINDOW_HIGTH - 64,
                                                                        WINDOW_WIDTH,
                                                                        50)];
    toolbar.image = [UIImage imageNamed:@"personInfo_toolbar.png"];
    toolbar.userInteractionEnabled = YES;
    [self.view addSubview:toolbar];
    
    UIButton *giftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    giftBtn.frame = CGRectMake(26, 3, 28, 28);
    [giftBtn setBackgroundImage:[UIImage imageNamed:@"personbarPresent.png"] forState:UIControlStateNormal];
    [giftBtn addTarget:self action:@selector(sendGiftBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *giftLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 31, 80, 9)];
    giftLabel.backgroundColor = [UIColor clearColor];
    giftLabel.textColor = [UIColor whiteColor];
    giftLabel.textAlignment = NSTextAlignmentCenter;
    giftLabel.text = @"送礼";
    giftLabel.font = [UIFont systemFontOfSize:10];
    
    [toolbar addSubview:giftBtn];
    [toolbar addSubview:giftLabel];
    
    UIButton *chatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    chatBtn.frame = CGRectMake(26 + 80, 3, 28, 28);
    [chatBtn setBackgroundImage:[UIImage imageNamed:@"personbarchat.png"] forState:UIControlStateNormal];
    [chatBtn addTarget:self action:@selector(chatBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *chatLabel = [[UILabel alloc]initWithFrame:CGRectMake(80, 31, 80, 9)];
    chatLabel.backgroundColor = [UIColor clearColor];
    chatLabel.textColor = [UIColor whiteColor];
    chatLabel.textAlignment = NSTextAlignmentCenter;
    chatLabel.text = @"聊天";
    chatLabel.font = [UIFont systemFontOfSize:10];
    
    [toolbar addSubview:chatBtn];
    [toolbar addSubview:chatLabel];
    
    UIButton *friendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    friendBtn.frame = CGRectMake(26 + 80*2, 3, 28, 28);
    [friendBtn setBackgroundImage:[UIImage imageNamed:@"personbarfriend.png"] forState:UIControlStateNormal];
    [friendBtn addTarget:self action:@selector(addFriendBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    
    friendLabel = [[UILabel alloc]initWithFrame:CGRectMake(80*2, 31, 80, 9)];
    friendLabel.backgroundColor = [UIColor clearColor];
    friendLabel.textColor = [UIColor whiteColor];
    friendLabel.textAlignment = NSTextAlignmentCenter;
    NSString *firendtitle = T_ADDCARE;
    if ([DataControl shareControl].currentFI != nil )
    {
        if ([[DataControl shareControl].careds IsShowArrContainsObject:
             [DataControl shareControl].currentFI.mail]) {
            
            firendtitle = T_CANCELCARE;
        }
    }
    
    friendLabel.text = firendtitle;
    friendLabel.font = [UIFont systemFontOfSize:10];
    
    [toolbar addSubview:friendBtn];
    [toolbar addSubview:friendLabel];
    
    UIButton *blockBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    blockBtn.frame = CGRectMake(26 + 80*3, 3, 28, 28);
    [blockBtn setBackgroundImage:[UIImage imageNamed:@"personbarblock.png"] forState:UIControlStateNormal];
    [blockBtn addTarget:self action:@selector(blockBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *blockLabel = [[UILabel alloc]initWithFrame:CGRectMake(80*3, 31, 80, 9)];
    blockLabel.backgroundColor = [UIColor clearColor];
    blockLabel.textColor = [UIColor whiteColor];
    blockLabel.textAlignment = NSTextAlignmentCenter;
    blockLabel.text = @"举报";
    blockLabel.font = [UIFont systemFontOfSize:10];
    
    [toolbar addSubview:blockBtn];
    [toolbar addSubview:blockLabel];
}


#pragma mark - button selector-
- (void)handleTap:(UITapGestureRecognizer *)recognizer
{
    if ([DataControl shareControl].currentFI == nil) {
        return;
    }
    
    
    BigImageInfo *binfo = [[DataControl shareControl].bigHIDS SearchBigImageByMail:
                           [DataControl shareControl].currentFI.mail];
    if (binfo != nil) {
        NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
        float nowinterval = [dat timeIntervalSince1970];
        
        if (nowinterval - binfo.updatetime - UPDATE_BIGIMAGE_INTERVAL > 0.001f ) {
            [[ViewManager sharedViewManager] showProgressHUDWithStatus:@"" withView:self.view];
            
            [[DataControl shareControl].bigHIDS.bigimageDic removeObjectForKey:
             [DataControl shareControl].currentFI.mail];
            
            [[DataControl shareControl].bigHIDS SearchBigImageByMail:
             [DataControl shareControl].currentFI.mail];
            
            isReadingbigimage = true;
            readbigcount = 0;
        }
        else
        {
            UIImage *bigimage = [UIImage imageWithContentsOfFile:binfo.url];
            if (bigimage == nil) {
                bigimage = [UIImage imageNamed:@"default_head.png"];
            }
            
            MyPhoto *photo = [[MyPhoto alloc] initWithImage:bigimage];
            MyPhotoSource *source = [[MyPhotoSource alloc] initWithPhotos:[NSArray arrayWithObjects:photo, nil]];
            EGOPhotoViewController *photoController = [[EGOPhotoViewController alloc] initWithPhotoSource:source];
            UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:photoController];
            
            navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
            navController.modalPresentationStyle = UIModalPresentationFullScreen;
            [self presentViewController:navController animated:YES completion:nil];
        }
    }
    else
    {
        [[ViewManager sharedViewManager] showProgressHUDWithStatus:@"" withView:self.view];
        
        isReadingbigimage = true;
        readbigcount = 0;
    }
}

-(void)ReadBigImageSucess
{
    if (!isReadingbigimage) {
        return;
    }
    
    isReadingbigimage = false;
    readbigcount = 0;
    
    [[ViewManager sharedViewManager] dismissProgressHUD];
    
    if ([DataControl shareControl].currentFI == nil) {
        return;
    }
    
    BigImageInfo *binfo = [[DataControl shareControl].bigHIDS SearchBigImageByMail:
                           [DataControl shareControl].currentFI.mail];
    
    if (binfo == nil) {
        return;
    }
    
    UIImage *bigimage = [UIImage imageWithContentsOfFile:binfo.url];
    if (bigimage == nil) {
        bigimage = [UIImage imageNamed:@"default_head.png"];
    }
    
    MyPhoto *photo = [[MyPhoto alloc] initWithImage:bigimage];
    MyPhotoSource *source = [[MyPhotoSource alloc] initWithPhotos:[NSArray arrayWithObjects:photo, nil]];
    EGOPhotoViewController *photoController = [[EGOPhotoViewController alloc] initWithPhotoSource:source];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:photoController];
    
    navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    navController.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:navController animated:YES completion:nil];
    
    [self refreshView];
}

-(void)blackBtnClick
{
    
}

-(void)backButtonPressed
{
    [[ViewManager sharedViewManager] backView:self];
}

-(void)sendGiftBtnPressed:(id)sender
{
    [[netManager sharedNetManager].sendp SendMainIndex:ID_MI_GIFT
                                       WithSecondIndex:GI_GET];
    
    [DataControl shareControl].giftInfoDS.strSenderMail =
    [DataControl shareControl].currentFI.mail;
    
    if (![[DataControl shareControl].currentFI.mail isEqualToString:@"jingling"]) {
//        [[ViewManager sharedViewManager] showView:VI_GIFTLIST
//                                 withIsRemoveCurV:false
//                                    withDirection:VD_RIGHT];
        
        [[DataControl shareControl].giftInfoDS SetShowArrByListID:1];
        
        [[ViewManager sharedViewManager] showView:VI_GIFTLISTINFO
                                 withIsRemoveCurV:false
                                    withDirection:VD_RIGHT];
        
        [[netManager sharedNetManager].sendgiftLL sendGiftLL:1];
        
        [[netManager sharedNetManager].sendPersonRC sendReadCoin];
    }
    else
    {
        [[ViewManager sharedViewManager] showFailHUDWithStatus:@"亲，碰碰精灵不要礼物哦"
                                                     withDelay:2
                                                      withView:self.view];
    }
    
}

-(void)addFriendBtnPressed:(id)sender
{
    if ([DataControl shareControl].currentFI == nil) {
        return;
    }
    
    isSearching = true;
    iWaitingTimer = 0;
    
    if ([[DataControl shareControl].careds IsShowArrContainsObject:
         [DataControl shareControl].currentFI.mail])
    {
        
        BeCareAlert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                 message:@"你确定取消关注此人吗"
                                                delegate:self
                                       cancelButtonTitle:@"取消"
                                       otherButtonTitles:@"确定",nil];
        [BeCareAlert show];
        
    }
    else
    {
        [[DataControl shareControl].LCDS addLogicCommand:LC_ADDFIREND];
        
        [[ViewManager sharedViewManager] showSuccessProgressHUDWithStatus:@"关注中"
                                                                 withView:self.view];
    }
}

-(void)chatBtnPressed:(id)sender
{
    if ([DataControl shareControl].currentFI == nil) {
        return;
    }
    
    NSMutableArray *chatarr = [[DataControl shareControl].chatDS GetArrByKey:
                               [DataControl shareControl].currentFI.mail];
    if (chatarr == nil)
    {
        chatarr = [[NSMutableArray alloc] init];
        [[DataControl shareControl].chatDS SetChatDicArr:chatarr withKey:
         [DataControl shareControl].currentFI.mail];
        [[DataBaseCtrol shareControl].chatuserdatabase insertChatDic:[DataControl shareControl].currentFI.mail
                                                         withIsGroup:false];
        
        
    }
    
    [DataControl shareControl].chatDS.currentChatArr = chatarr;
    
    [[ViewManager sharedViewManager] showView:VI_CHAT
                             withIsRemoveCurV:false
                                withDirection:VD_RIGHT];
}

-(void)blockBtnPressed:(id)sender
{
    if ([DataControl shareControl].currentFI == nil)
    {
        return;
    }
    
    ReportAlert = [[UIAlertView alloc] initWithTitle:@"提示"
                                             message:@"你确定举报此人吗"
                                            delegate:self
                                   cancelButtonTitle:@"取消"
                                   otherButtonTitles:@"确定",nil];
    [ReportAlert show];
    
    
}

-(void)ReportSuccess
{
    if (isSearching)
    {
        iWaitingTimer = 0;
        isSearching = false;
        
        [[ViewManager sharedViewManager] ChangeHUDShowSuccess:@"举报成功"];
    }
}

#pragma mark - tableView DataSource -
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 3) {
        PersonalSignCell * perSignCell = (PersonalSignCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
        return (perSignCell.contentView.frame.size.height);//个性签名cell返回的高度
    }else{
        return 44;
    }
    
    return 0;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * CellIdentifier = @"Cell";
    static NSString * perSignIdentifier = @"signIdentifier";
    if (indexPath.row == 3) {
        PersonalSignCell * signCell = [tableView dequeueReusableCellWithIdentifier:perSignIdentifier];
        
        if (signCell == nil) {
            signCell = [[PersonalSignCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:perSignIdentifier];
            
        }
        signCell.contentView.frame = CGRectMake(0, 0, 320, 44);
        [signCell setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell.png"]]];
        signCell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        signCell.titleLabel.text = @"个人签名";
        signCell.detailLabel.text = [DataControl shareControl].currentFI.strSign;
        [signCell changeCellHeight];//改变cell的高度
        
        return signCell;
        
    }else{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] ;
            [cell setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell.png"]]];
            UIImageView *selectImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellpress.png"]];
            [cell setSelectedBackgroundView:selectImageView];
            
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.textLabel.textAlignment = UITextAlignmentCenter;
        cell.detailTextLabel.textAlignment = UITextAlignmentLeft;
        
        if (indexPath.row == 2) {
            cell.textLabel.text = @"他的礼物";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            
            for (UIView *v in cell.contentView.subviews) {
                [v removeFromSuperview];
            }
            
            NSArray *giftarr = [NSArray arrayWithArray:
                                [[DataControl shareControl].giftStroageDS GetGSArr]];
            
            int startpos = 140;
            if (giftarr.count < 4) {
                startpos = 260 - giftarr.count * 30;
            }
            
            for (int i = 0; i < giftarr.count && i < 4; ++i) {
                giftStroageDataInfo *gsinfo = [giftarr objectAtIndex:i];
                UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(startpos + i * 30, 5, 30, 30)];
                NSString *strpath = [[DataControl shareControl].giftInfoDS searchGiftImagePath:gsinfo.strgiftid];
                
                if ([strpath isEqualToString:@""]) {
                    imageview.image = [UIImage imageNamed:@"gift_default.png"];
                }
                else
                {
                    imageview.image = [UIImage imageWithContentsOfFile:strpath];
                }
                
                [cell.contentView addSubview:imageview];
            }
        }
        else if (indexPath.row == 0)
        {
            cell.textLabel.text = @"年龄";
            if ([DataControl shareControl].currentFI != nil)
            {
                cell.detailTextLabel.text = [NSString stringWithFormat:@"%d 岁",
                                             [DataControl shareControl].currentFI.age];
            }
        }
        else if(indexPath.row == 1)
        {
            cell.textLabel.text = @"城市";
            if ([DataControl shareControl].currentFI != nil)
            {
                cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ %@",
                                             getProvinceFromMapArr([DataControl shareControl].currentFI.province),
                                             getCityFromMapArr([DataControl shareControl].currentFI.province,
                                                               [DataControl shareControl].currentFI.city)];
            }
            
        }else if(indexPath.row == 4){
            cell.textLabel.text = @"个人空间";
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        
        return cell;

    }
    
    return nil;
}


#pragma mark -table delegate-
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 4) {
        
        [[DataControl shareControl].fcPersonDS setCurshow:
         [[DataControl shareControl].fcPersonDS getShowArrByMail:
          [DataControl shareControl].currentFI.mail]];
        
        [[netManager sharedNetManager].sendFCNewL SendNewsLength:[DataControl shareControl].currentFI.mail];
        
        [[ViewManager sharedViewManager] showView:VI_PERSONALSTATUS
                                 withIsRemoveCurV:false
                                    withDirection:VD_RIGHT];
    }
    else if (indexPath.row == 2)
    {
        [[ViewManager sharedViewManager] showView:VI_GIFT_STROAGE
                                 withIsRemoveCurV:false
                                    withDirection:VD_RIGHT];
    }
}

#pragma mark -private fun-

-(void)UpdateHeadImage
{
    [self reloadHeadView];
    [mtablev reloadData];
}

-(void)addFriendSucess
{
    if (isSearching)
    {
        iWaitingTimer = 0;
        isSearching = false;
        
        [[ViewManager sharedViewManager] ChangeHUDShowSuccess:@"关注成功"];
    }
    
    [self refreshView];
}

-(void)UICustomTick
{
    if(isSearching)
    {
        if (iWaitingTimer < WAIT_TIMMER)
        {
            ++iWaitingTimer;
        }
        else
        {
            iWaitingTimer = 0;
            isSearching = false;
            
            [[ViewManager sharedViewManager] dismissProgressHUD];
        }
    }
    
    if (isReadingbigimage) {
        if (readbigcount < WAIT_TIMMER) {
            ++readbigcount;
        }
        else
        {
            readbigcount = 0;
            isReadingbigimage = false;
            
            [[ViewManager sharedViewManager] dismissProgressHUD];
        }
    }
}

-(void)deleteFirendSucess
{
    if (isSearching)
    {
        iWaitingTimer = 0;
        isSearching = false;
        
        [[ViewManager sharedViewManager] ChangeHUDShowSuccess:@"取消成功"];
    }
    
    [self refreshView];
}

//修改添加关注label的text
-(void)refreshView
{
    if ([DataControl shareControl].currentFI != nil)
    {
        if ([[DataControl shareControl].careds IsShowArrContainsObject:
             [DataControl shareControl].currentFI.mail])
        {
            friendLabel.text = @"取消关注";
        }
        else
        {
            friendLabel.text = @"添加关注";
        }
        
        [self reloadHeadView];
        [mtablev reloadData];
    }
}

-(void)viewWillShow
{
    [[DataControl shareControl].giftStroageDS delAllArr];
    
    [self refreshView];
    
    [[DataControl shareControl] RefreshInfoByNet:
     [DataControl shareControl].currentFI.mail];
    
    if ([DataControl shareControl].currentFI != nil) {
        [[netManager sharedNetManager].sendgiftStroage
         sendGiftGetTheStroage:[DataControl shareControl].currentFI.mail];
    }
    
}

#pragma mark -alertview delegate-
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex != [alertView cancelButtonIndex])
    {
        
        if (alertView == ReportAlert) {
            [[DataControl shareControl] SetReportMail:
             [DataControl shareControl].currentFI.mail];
            
            [[DataControl shareControl].LCDS addLogicCommand:LC_REPORT];
            
            [[ViewManager sharedViewManager] showSuccessProgressHUDWithStatus:@"举报中"
                                                                     withView:self.view];
            
            isSearching = true;
            iWaitingTimer = -20;
        }
        else if(alertView == BeCareAlert)
        {
            [[DataControl shareControl].LCDS addLogicCommand:LC_DELETEFIREND];
            
            [[ViewManager sharedViewManager] showSuccessProgressHUDWithStatus:@"取消中"
                                                                     withView:self.view];
        }
        
    }
}
@end
